package com.coder.shop.rpc.service.impl;

import com.coder.common.annotation.BaseService;
import com.coder.common.base.BaseServiceImpl;
import com.coder.common.util.MD5Util;
import com.coder.shop.dao.mapper.UcenterUserDetailsMapper;
import com.coder.shop.dao.mapper.UcenterUserMapper;
import com.coder.shop.dao.model.UcenterUser;
import com.coder.shop.dao.model.UcenterUserDetails;
import com.coder.shop.dao.model.UcenterUserExample;
import com.coder.shop.rpc.api.UcenterUserService;

import java.util.Date;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* UcenterUserService实现
* @Author liuzhimin
* @Date Created by liuzhimin on 2018/5/7.
* @Description
*/
@Service
@Transactional
@BaseService
public class UcenterUserServiceImpl extends BaseServiceImpl<UcenterUserMapper, UcenterUser, UcenterUserExample> implements UcenterUserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UcenterUserServiceImpl.class);

    @Autowired
    UcenterUserMapper ucenterUserMapper;
    
    @Autowired
    UcenterUserDetailsMapper ucenterUserDetailsMapper;

    @Transactional
	@Override
	public void register(String phone, String smscode, String password) {
		UcenterUser user = new UcenterUser();
		user.setNickname(phone);
		user.setSalt(MD5Util.md5(UUID.randomUUID().toString()));
		user.setPassword(MD5Util.md5(password+user.getSalt()));
		user.setCreateTime(new Date());
		user.setUserName(phone);
		
		//保存用户表
		ucenterUserMapper.insertSelective(user);
		
		//用户详情表
		UcenterUserDetails details = new UcenterUserDetails();
		details.setUserId(user.getUserId());
		details.setPhone(phone);
		ucenterUserDetailsMapper.insertSelective(details);
	}

}